import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_screenutil/src/size_extension.dart';
import '../../../../common/cpn/cpn_view_state.dart';
import '../../../../common/cpn/sliver_app_bar.dart';
import 'feedback_history_logic.dart';

class FeedbackHistoryPage extends CpnViewState<FeedbackHistoryLogic> {
  FeedbackHistoryPage({Key? key}) : super(key: key, bindViewState: false);
  final List<FeedbackHistory> feedbackHistories = [
    FeedbackHistory(
      type: '问题反馈',
      content: '应用启动时崩溃',
      isAnonymous: true,
      response: '已修复，请更新到最新版本',
      timestamp: DateTime.now(),
    ),
    FeedbackHistory(
      type: '功能建议',
      content: '希望增加夜间模式',
      isAnonymous: false,
      response: '正在考虑，谢谢建议',
      timestamp: DateTime.now().subtract(Duration(days: 1)),
    ),
  ];

  @override
  Widget buildBody(BuildContext context) {
    return CustomScrollView(
      slivers: [
        commonSliverAppBar(
          title: '反馈历史',
        ),
        SliverPadding(
          padding: EdgeInsets.all(10.w),
          sliver: SliverList(
            delegate: SliverChildBuilderDelegate(
                  (context, index) {
                final feedback = feedbackHistories[index];
                return Card(
                  margin: EdgeInsets.all(10.w),
                  child: Padding(
                    padding: EdgeInsets.all(15.w),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          feedback.type,
                          style: TextStyle(fontSize: 30.sp, fontWeight: FontWeight.bold),
                        ),
                        SizedBox(height: 10.h),
                        Text(
                          '问题描述:${feedback.content}',
                          style: TextStyle(fontSize: 27.sp),
                        ),
                        SizedBox(height: 10.h),
                        Text(
                          '匿名: ${feedback.isAnonymous ? '是' : '否'}',
                          style: TextStyle(fontSize: 27.sp),
                        ),
                        SizedBox(height: 10.h),
                        Text(
                          '回复: ${feedback.response}',
                          style: TextStyle(fontSize: 27.sp),
                        ),
                        SizedBox(height: 10.h),
                        Text(
                          '时间: ${feedback.timestamp.toString()}',
                          style: TextStyle(fontSize: 27.sp),
                        ),
                      ],
                    ),
                  ),
                );
              },
              childCount: feedbackHistories.length,
            ),
          ),
        ),
      ],
    );
  }
}

class FeedbackHistory {
  final String type;
  final String content;
  final bool isAnonymous;
  final String response;
  final DateTime timestamp;

  FeedbackHistory({
    required this.type,
    required this.content,
    required this.isAnonymous,
    required this.response,
    required this.timestamp,
  });
}
